//
//  PushViewController.m
//  UI_A段项目_iDaily Watch
//
//  Created by 徐继垚 on 14-10-13.
//  Copyright (c) 2014年 徐继垚. All rights reserved.
//

#import "PushViewController.h"
#import "PUSHCELLViewController.h"
#import "UIButton+WebCache.h"

@interface PushViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation PushViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.dataSource = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction:)];
    
    self.navigationItem.leftBarButtonItem = item;
    [self CreateTableView];
    // Do any additional setup after loading the view.
}
#pragma mark-
#pragma mark 创建Tableview
-(void)CreateTableView
{
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 568) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
    [_tableView release];
    
    
    
    
    
}
#pragma mark-
#pragma mark TableView datasource deleget
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 0) {
        
        static NSString * indentifer = @"cell";
        PUSHCELLViewController  * cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
        if (!cell) {
            cell = [[[PUSHCELLViewController alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifer]autorelease];
        }
        NSLog(@"%lu", (long)_index);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (_index == 0) {
            
            [cell.button setBackgroundImageWithURL:[NSURL URLWithString:[_dataSource[_index]bigimage2]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"1111.png"]];
        }
        else
        {
            [cell.button setBackgroundImageWithURL:[NSURL URLWithString:[_dataSource[_index]videoimage]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"1111.png"]];
        }
        cell.toplabel.text = [_dataSource[_index]source];
        cell.titelabel.text = [_dataSource[_index]title];
        cell.daylabel.text = [_dataSource[_index]days];
        cell.subtitelabel.text = [_dataSource[_index]maker];
        return cell;
    }
    else
    {
        static NSString * indentifer = @"cell11";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
        if (!cell) {
            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifer]autorelease];
        }
    
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
        _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 260, 320, 568)];
        
       
        
        NSString * html = [_dataSource[_index]content];
        [_webView loadHTMLString:html baseURL:nil];
        [self.tableView addSubview:_webView];
        [_webView reload];
        return cell;
        
    }
    return 0;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 0.1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 260;
    }
    return 568;
    
}

-(void)buttonAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
